﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SampleEventAgregator.Models;
using SampleEventAgregator.Services;

namespace SampleEventAgregator.ViewModels
{
    public class MainViewModel : Microsoft.Practices.Prism.StoreApps.ViewModel
    {
        Services.Service service = new Service();
        private Microsoft.Practices.Prism.PubSubEvents.IEventAggregator Aggregator;

        public System.Collections.ObjectModel.ObservableCollection<Models.ModelPost> Posts { get; set; } 
        
        public MainViewModel()
        {
            Posts = new ObservableCollection<ModelPost>();
            service = new Service();
            Aggregator = App.EventAggregator;
            Aggregator.GetEvent<SampleEvent.EventGetPost>().Subscribe(Recived);
        }

        private void Recived(Models.ModelPost input)
        {
            Posts.Add(input);
        }

        public void Loaded()
        {
            service.LoadListNews();
        }
    }
}
